// page/submitInfo/submitInfo.js
// pages/details/details.js
var appDatas = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    reportDetail: [],
    pictures: [],
    devices: [],
    previewImgs: []
  },
  //预览图片
  previewImg(e) {
    wx.previewImage({
      current: this.data.previewImgs[e.target.dataset.imageindex], // 当前显示图片的http链接
      urls: this.data.previewImgs // 需要预览的图片http链接列表
    })
  },


  //跳转到评价页面
  toSetEvaluate(){
    wx.navigateTo({
      url: '/page/evaluation/evaluation?reportId=' + this.data.reportDetail.reportId,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("options:", options);
    console.log("ReportId:", options.ReportId == null);
    if (options.ReportId == null) {
      wx.request({
        url: 'https://www.hankooktire-wx.com.cn:8443/htwx-api/UserController/findFactoryLocationById',
        data: {
          factorylocationId: appDatas.globalData.reportArr[options.index].locationId
        },
        success: data => {
          this.setData({
            devices: data.data
          })
          console.log(data)
        }
      })
    } else {
      wx.request({
        url: 'https://www.hankooktire-wx.com.cn:8443/htwx-api/UserController/findFactoryLocationById',
        data: {
          factorylocationId: appDatas.globalData.reportArr[options.index].locationId
        },
        success: data => {
          this.setData({
            devices: data.data
          })
          console.log(data)
        }
      })
    }

    var spilts = null;
    if (appDatas.globalData.reportArr[options.index].picture != null) {
      spilts = appDatas.globalData.reportArr[options.index].picture.split(",");
    }
    console.log(spilts)
    //设置数据到页面
    this.setData({
      reportDetail: appDatas.globalData.reportArr[options.index],
      pictures: spilts
    })
    let pic = "";
    for (var index in this.data.pictures) {
      pic = 'http://115.231.73.155:8080/images/' + this.data.pictures[index]
      this.setData({
        previewImgs: this.data.previewImgs.concat(pic)
      })
    }
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})